/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.liquidByte.trafficMustang.server.dataModel;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import org.liquidByte.trafficMustang.server.dataModel.enums.TrechoSituacao;

/**
 *
 * @author Alexandre
 */
@Entity
@Table(name = "trec")
public class Trecho implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "TREC_ID")
    private Long trecId;
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(column=@Column(name="TREC_EMBQ_LONG"), name="longitude"),
        @AttributeOverride(column=@Column(name="TREC_EMBQ_LAT"), name="latitude")
    })
    private Localizacao embarque;
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(column=@Column(name="TREC_DEMBQ_LONG"), name="longitude"),
        @AttributeOverride(column=@Column(name="TREC_DEMBQ_LAT"), name="latitude")
    })
    private Localizacao desembarque;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "trecho", orphanRemoval=true)
    private List<TrechoHistorico> trechoHistoricoList;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TREC_SIT_ID")
    @Enumerated(EnumType.ORDINAL)
    private TrechoSituacao trecSitId;
    @JoinColumn(name = "PASG_ID", referencedColumnName = "USR_ID")
    @ManyToOne(optional = false)
    private Passageiro pasgId;
    @JoinColumn(name = "DESLC_ID", referencedColumnName = "DESLC_ID")
    @ManyToOne(optional = false)
    private Deslocamento deslcId;
    @OneToMany(mappedBy = "trecId")
    private List<Avaliacao> avaliacaoList;

    public Trecho() {
    }

    public Trecho(Long trecId) {
        this.trecId = trecId;
    }

    public Trecho(Long trecId, Localizacao embarque, Localizacao desembarque) {
        this.trecId = trecId;
        this.embarque = embarque;
        this.desembarque = desembarque;
    }

    public Long getTrecId() {
        return trecId;
    }

    public void setTrecId(Long trecId) {
        this.trecId = trecId;
    }

    public Localizacao getDesembarque() {
        return desembarque;
    }

    public void setDesembarque(Localizacao desembarque) {
        this.desembarque = desembarque;
    }

    public Localizacao getEmbarque() {
        return embarque;
    }

    public void setEmbarque(Localizacao embarque) {
        this.embarque = embarque;
    }

    public List<TrechoHistorico> getTrechoHistoricoList() {
        return trechoHistoricoList;
    }

    public void setTrechoHistoricoList(List<TrechoHistorico> trechoHistoricoList) {
        this.trechoHistoricoList = trechoHistoricoList;
    }

    public TrechoSituacao getTrecSitId() {
        return trecSitId;
    }

    public void setTrecSitId(TrechoSituacao trecSitId) {
        this.trecSitId = trecSitId;
    }

    public Passageiro getPasgId() {
        return pasgId;
    }

    public void setPasgId(Passageiro pasgId) {
        this.pasgId = pasgId;
    }

    public Deslocamento getDeslcId() {
        return deslcId;
    }

    public void setDeslcId(Deslocamento deslcId) {
        this.deslcId = deslcId;
    }

    public List<Avaliacao> getAvaliacaoList() {
        return avaliacaoList;
    }

    public void setAvaliacaoList(List<Avaliacao> avaliacaoList) {
        this.avaliacaoList = avaliacaoList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (trecId != null ? trecId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Trecho)) {
            return false;
        }
        Trecho other = (Trecho) object;
        if ((this.trecId == null && other.trecId != null) || (this.trecId != null && !this.trecId.equals(other.trecId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.liquidByte.trafficMustang.server.dataModel.Trecho[ trecId=" + trecId + " ]";
    }
}
